package com.jmda.platform.commom;

import org.springframework.core.io.ResourceLoader;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;

@Service("ResourceLoaderPath")
public class ResourcePathConfig {
    @Resource
    ResourceLoader res;
    private String worklistPath = "/WEB-INF/MDA/worklist";
    private String templateSystemPath = "/jmda-ftl/system/";
    private String templateEformPath = "/WEB-INF/pages";
    private String applicationPath = "/WEB-INF/MDA/application";
    private String formPath = "/WEB-INF/MDA/form";

    //获取表单类xml文件的路径
    public String getFormPath() throws IOException {
        org.springframework.core.io.Resource path = res.getResource(formPath);
        File file = path.getFile();
        if(!file.exists()){
        	file.mkdirs();
        }
        String logoRealPathDir = file.getAbsolutePath();
        String realDir = logoRealPathDir + File.separator;
        realDir = realDir.replaceAll("\\\\", "/");
        return realDir;
    }

    //获取列表类xml文件的路径
    public String getWorklistPath() throws IOException {
        org.springframework.core.io.Resource path = res.getResource(worklistPath);
        File file = path.getFile();
        if(!file.exists()){
        	file.mkdirs();
        }
        String logoRealPathDir = file.getAbsolutePath();
        String realDir = logoRealPathDir + File.separator;
        realDir = realDir.replaceAll("\\\\", "/");
        return realDir;
    }

    public String getTemplateSystemPath() throws IOException {
        return templateSystemPath;
    }

    public String getTemplateEformPath() throws IOException {
        org.springframework.core.io.Resource path = res.getResource(templateEformPath);
        File file = path.getFile();
        if(!file.exists()){
        	file.mkdirs();
        }
        String logoRealPathDir = file.getAbsolutePath();
        String realDir = logoRealPathDir + File.separator;
        return realDir;
    }

    public String getRealPath(String classPath) throws IOException {
        org.springframework.core.io.Resource path = res.getResource(classPath);
        File file = path.getFile();
        String logoRealPathDir = file.getAbsolutePath();
        String realDir = logoRealPathDir + File.separator;
        return realDir;
    }

    public String getApplicationPath() throws IOException {
        org.springframework.core.io.Resource path = res.getResource(applicationPath);
        File file = path.getFile();
        if(!file.exists()){
        	file.mkdirs();
        }
        String logoRealPathDir = file.getAbsolutePath();
        String realDir = logoRealPathDir + File.separator;
        return realDir;
    }

}
